/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.security.MessageDigest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DEVAIR
 */
public abstract class AppUtil {

    public static Calendar dataSimples(String dataString) {
        Calendar data = null;        

        // fazendo a conversão da data
        try {
            Date date = new SimpleDateFormat("dd/MM/yyyy")
                    .parse(dataString);
            data = Calendar.getInstance();
            data.setTime(date);
        } catch (ParseException e) {

        }

        return data;
    }

    public static String criptografa(String senha) {
        String senhaCriptografada = null;

        try {
            MessageDigest algorithm;
            algorithm = MessageDigest.getInstance("SHA-256");
            byte messageDigest[] = algorithm.digest(senha.getBytes("UTF-8"));

            StringBuilder hexString = new StringBuilder();
            for (byte b : messageDigest) {
                hexString.append(String.format("%02X", 0xFF & b));
            }
            senhaCriptografada = hexString.toString();

        } catch (Exception ex) {
            Logger.getLogger(AppUtil.class.getName()).log(Level.SEVERE, null, ex);
        }

        return senhaCriptografada;

    }
}
